<?php

class SQLConnection {

    private static $type = null;

    private function __construct() {
        
    }

    public static function open() {
        $sqlConfig = Config::get('SQL');
        self::$type = $sqlConfig['type'];
        switch ($sqlConfig['type']) {
            case 'mysql':
                $connectionString = "mysql:host={$sqlConfig['host']};dbname={$sqlConfig['dbname']}";
                break;
            case 'sqlite':
                $connectionString = "sqlite:{$sqlConfig['dbname']}";
                break;
            default:
                return false;
        }
        return new PDO(
                $connectionString,
                $sqlConfig['user'],
                $sqlConfig['pass'],
                array(
                    PDO::ATTR_PERSISTENT => $sqlConfig['persistent'],
                    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
                )
        );
    }

}

?>
